//
//  CompanyDetailView.m
//  陶瓷
//
//  Created by 王戈 on 15/7/14.
//  Copyright (c) 2015年 王戈. All rights reserved.
//
#define margin 15

#import "CompanyDetailView.h"

@interface CompanyDetailView ()

@property (nonatomic, strong) UIButton *nameLabel;
@property (nonatomic, strong) UILabel *deltailLabel;

@end

@implementation CompanyDetailView

- (id)initWithCoder:(NSCoder *)aDecoder {
    if ((self = [super initWithCoder:aDecoder])) {
        [self setup];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup {
    _nameLabel = [UIButton buttonWithType:UIButtonTypeCustom];
    _nameLabel.userInteractionEnabled = NO;
    [self addSubview:_nameLabel];
    
    _deltailLabel = [[UILabel alloc] init];
    [self addSubview:_deltailLabel];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    _nameLabel.frame = CGRectMake(0, margin, self.width, 30);
    [_nameLabel setTitleEdgeInsets:UIEdgeInsetsMake(20, 0, _nameLabel.width - 40, 0)];
    
    CGFloat detailHeight = [_deltailLabel.text sizeWithfont:_deltailLabel.font maxSize:CGSizeMake(self.width - 2*margin, CGFLOAT_MAX)].height;
    _deltailLabel.frame = CGRectMake(margin, CGRectGetMaxY(_nameLabel.frame), self.width- 2 * margin, detailHeight);
    
    self.height = CGRectGetMaxY(_deltailLabel.frame) + 2 * margin;
}

- (void)setCompany:(CompanyModel *)company {
    _company = company;
    
    [_nameLabel setTitle:company.Name forState:UIControlStateNormal];
    
    _deltailLabel.text = [NSString stringWithFormat:@"公司品牌 : %@\n公司名称 : %@\n联系人 : %@\n联系电话 : %@\n公司地址 : %@",company.Brand ,company.Name ,company.LinkMan, company.ContactNumber, company.Address];
}
@end
